<body></body>
<script>
function delay(ms) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, ms)
  })
}
const {body} = document
function lights() {
  return delay(0)
    .then(() => body.style.backgroundColor='red')
    .then(() => delay(3000))
    .then(() => body.style.backgroundColor='yellow')
    .then(() => delay(1000))
    .then(() => body.style.backgroundColor='green')
    .then(() => delay(3000))
    .then(() => body.style.backgroundColor='yellow')
    .then(() => delay(1000))
    .then(() => lights())
}
lights()
</script>